package com.example.x5webviewdemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.x5webviewdemo.R;
import com.example.x5webviewdemo.utils.X5WebView;

/**
 * @作者: njb
 * @时间: 2019/11/8 10:32
 * @描述: 用于演示X5webView的基本使用
 */
public class X5WebViewActivity extends Activity {
    private X5WebView webView;
    private TextView textView;
    //private String url = "https://1111.tmall.com/";
    //private String url = "https://h5.m.taobao.com/";
    private String url = "https://www.jd.com/";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.filechooser_layout);
        initWebView();
        initListener();
    }



    private void initWebView() {
        webView = findViewById(R.id.web_filechooser);
        textView = findViewById(R.id.tv_open);
        webView.loadUrl(url);
    }

    private void initListener() {
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openFileChooseProcess();
            }
        });
    }

    /**
     * 打开文件管理器
     */
    private void openFileChooseProcess() {
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("application/vnd.ms-excel");
        //i.setType("*/*");
        startActivityForResult(Intent.createChooser(i, "test"), 0);
    }

    /**
     * 确保注销配置能够被释放
     */
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        if (this.webView != null) {
            webView.destroy();
        }
        super.onDestroy();
    }
}
